using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient ;
using System.Data;
namespace WindowsApplication1
{
	/// <summary>
	/// Summary description for Form14.
	/// </summary>
	public class Due_Date : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button btnupdate;
        private Button btn_close;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Due_Date()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.button1 = new System.Windows.Forms.Button();
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            this.label1 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.btnupdate = new System.Windows.Forms.Button();
            this.btn_close = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(310, 25);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(70, 25);
            this.button1.TabIndex = 2;
            this.button1.Text = "Search";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // dataGrid1
            // 
            this.dataGrid1.DataMember = "";
            this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGrid1.Location = new System.Drawing.Point(15, 65);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.Size = new System.Drawing.Size(720, 190);
            this.dataGrid1.TabIndex = 3;
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(30, 30);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(100, 23);
            this.label1.TabIndex = 4;
            this.label1.Text = "Student id";
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(145, 30);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(100, 20);
            this.textBox1.TabIndex = 5;
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(105, 295);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 6;
            this.button2.Text = "By Cash";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(305, 290);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(75, 23);
            this.button3.TabIndex = 7;
            this.button3.Text = "By Cheque";
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // btnupdate
            // 
            this.btnupdate.Location = new System.Drawing.Point(105, 330);
            this.btnupdate.Name = "btnupdate";
            this.btnupdate.Size = new System.Drawing.Size(75, 23);
            this.btnupdate.TabIndex = 8;
            this.btnupdate.Text = "Update";
            this.btnupdate.Visible = false;
            this.btnupdate.Click += new System.EventHandler(this.btnupdate_Click);
            // 
            // btn_close
            // 
            this.btn_close.Location = new System.Drawing.Point(305, 330);
            this.btn_close.Name = "btn_close";
            this.btn_close.Size = new System.Drawing.Size(75, 23);
            this.btn_close.TabIndex = 9;
            this.btn_close.Text = "Close";
            this.btn_close.UseVisualStyleBackColor = true;
            this.btn_close.Click += new System.EventHandler(this.btn_close_Click);
            // 
            // Due_Date
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(747, 406);
            this.Controls.Add(this.btn_close);
            this.Controls.Add(this.btnupdate);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.dataGrid1);
            this.Controls.Add(this.button1);
            this.Name = "Due_Date";
            this.Text = "Payment Due date";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Load += new System.EventHandler(this.Due_Date_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion
		SqlConnection con;
		SqlDataAdapter da;
		DataSet ds;
		SqlCommandBuilder scmd;


		private void button1_Click(object sender, System.EventArgs e)
		{
			
			da=new SqlDataAdapter("Select stu_id,tap,type from Paydet where stu_id='" + textBox1.Text + "' ",con);
			ds=new DataSet();
			da.Fill(ds,"Paydet");
			dataGrid1.DataSource=ds.Tables[0];
			
			
		}

		private void Due_Date_Load(object sender, System.EventArgs e)
		{
            con = new SqlConnection();
            con.ConnectionString = "Data Source=ss.cs.luc.edu;Initial Catalog=PrepDB;User ID=ueshwara; pwd=p47807";
            con.Open();	
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			btnupdate .Visible =true;
			da=new SqlDataAdapter("Select stu_id,tap,downpay,noi,dd1,dd2,dd3,amt1,amt2,amt3 from Paydet where stu_id='" + textBox1.Text + "' ",con);
			ds=new DataSet();
			da.Fill(ds,"Paydet");
			dataGrid1.DataSource=ds.Tables[0];
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			
			da=new SqlDataAdapter("Select stu_id,tap,cheno,cheamt,chedate,drawn from Paydet where stu_id='" + textBox1.Text + "' ",con);
			ds=new DataSet();
			da.Fill(ds,"Paydet");
			dataGrid1.DataSource=ds.Tables[0];
			
		}

		

		private void btnupdate_Click(object sender, System.EventArgs e)
		{
			dataGrid1.DataSource=ds.Tables[0];
			scmd=new SqlCommandBuilder(da);
			
			 da.Update(ds,"Paydet");
			MessageBox.Show("Record Updated");
		}

        private void btn_close_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

		
	}
}
